// pages/plugins/index/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modelList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  // 获取首页配置
  loadHomepageConfig() {
    var that = this;
    var data = {
      point_url: app.server.adminApi.getWxappHomepage
    };
    app.server.getConnect(data).then(function (res) {
      for (let i in res.data) {
        if (res.data[i]['id'] === 8) {
          that.setData({
            modelList: res.data[i]['plugUnitList']
          })
          break;
        }
      }
      wx.setStorageSync('pluginList', that.data.modelList);
      app.globalData.pluginList = that.data.modelList;
    })
  },

  // 页面跳转
  bindJumpToPage(e){
    this.getFormId(e);
    let url = '';
    if(e.currentTarget.id === '184'){
      url = '/pages/admin/plugins/customer/customer-list/customer-list';
    } else if (e.currentTarget.id === '185'){
      url = '/pages/admin/plugins/exam/list/index';
    } else if (e.currentTarget.id === '271'){
      url = '/pages/admin/plugins/tencentCloud/customer/list';
    }
    wx.navigateTo({
      url: url,
    })
  },

  // 子功能跳转
  bindToPluginPage(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadHomepageConfig();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadHomepageConfig();
    app.utils.initAdminWxappStyle(app, this);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
